package com.feng.zhihao.apigeteway.gateway.bean.impl.FIELD_TYPE;

import org.springframework.stereotype.Component;

import com.feng.zhihao.apigeteway.entity.InterfaceFieldInfo;
import com.feng.zhihao.apigeteway.gateway.bean.FIELD_TYPE;
import com.xiaoleilu.hutool.date.DateException;
import com.xiaoleilu.hutool.date.DateUtil;
import com.xiaoleilu.hutool.util.StrUtil;

@Component("FIELD_TYPE_DATE")
public class FIELD_TYPE_DATE implements FIELD_TYPE {

	@Override
	public String validatorField(InterfaceFieldInfo fieldInfo, Object value) {
		try {
			DateUtil.parse(value.toString(),fieldInfo.getInterfaceFieldFormatting());
			return "";
		} catch (DateException e) {
			return StrUtil.format("字段:({}), 值:({}) 无法解析:({});\r\n", fieldInfo.getInterfaceFieldName(),value,fieldInfo.getInterfaceFieldFormatting());
		}
	}

}
